#include <blackbox/blackbox.h>
#include <blackbox/boxes/bperiodic.h>
#include <blackbox/cscheduler.h>
#include <blackbox/proxies.h>
#include <blackbox/connect.h>
#include <blackbox/cscheduler.h>

#include <buola/media/audio/baudiotestsrc.h>
#include <blackbox/boxes/io/bfilesrc.h>
#include <buola/media/audio/bpulsesink.h>
#include <buola/media/codec/bmp3decoder.h>

using namespace buola::blackbox;
using namespace buola;

int main(int pNArgs,char **pArgs)
{
    buola_init(pNArgs,pArgs);
    try
    {
        BFileSrc lFileSrc(io::file("/home/xavi/test/test.mp3"));
        BMP3Decoder lMP3Decoder;
    //    BAudioTestSrc lTestSrc;
        media::BPulseSink lPulseSink;
        bb_connect(lFileSrc.oData,lMP3Decoder.iData);
        bb_connect(lMP3Decoder.oWave,lPulseSink.iWave);
        //lMP3Decoder.ChangeState(BBox::STATE_ACTIVE);
        //lTestSrc.ChangeState(BBox::STATE_ACTIVE);
        //lPulseSink.ChangeState(BBox::STATE_ACTIVE);

        for(int i=0;i<1000;i++)
        {
            lFileSrc.CreateBuffer();
        }

        buola_main_loop();
        sleep(10);
    }
    catch(std::exception &pE)
    {
        msg_info() << "caught exception " << pE.what() << "\n";
    }
    return buola_finish();
}
